package com.wangrui.controller;


import com.wangrui.dto.AllClassGrade;
import com.wangrui.utils.Page;
import com.wangrui.pojo.ClassGrade;

import com.wangrui.service.ClassGradeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 王锐
 * @since 2020-07-10
 */
@Controller
@RequestMapping("/class")
public class ClassGradeController {
    @Autowired
    private ClassGradeService classGradeService;

    @RequestMapping("/classGradeList")
    public String classGradeListHtml()  {
        return "classGrade/classList";
    }
    @RequestMapping("/save")
    public String saveHtml()  {
        return "classGrade/save";
    }
    @RequestMapping("/update")
    public String updateHtml()  {
        return "classGrade/update";
    }


    @RequestMapping("/queryAllClassJson")
    @ResponseBody
    public List<ClassGrade> queryAllClassJson(){
        List<ClassGrade> list = classGradeService.queryMajorsJson();
        return list;
    }



    @RequestMapping("/queryAllClassGrades")
    public ResponseEntity<Map<String, Object>> queryAllclassGrades(
            @RequestParam("page")int page,
            @RequestParam("rows")int rows
    ) {
        Page<AllClassGrade> page1 = new Page<>();
        page1.setPageSize(rows);
        page1.setPageIndex(page);
        Map<String, Object> stringObjectMap = classGradeService.AllClassGrades(page1);
        return ResponseEntity.ok(stringObjectMap);
    }
    @RequestMapping("/classGradeSave")
    public ResponseEntity<Void> classGradeSave(ClassGrade classGrade)  {

        classGradeService.classGradeSave(classGrade);
        return new ResponseEntity<>(HttpStatus.CREATED);
    }

    @RequestMapping("/classGradeUpdate")
    public ResponseEntity<Void> classGradeUpdate(ClassGrade classGrade)  {
        classGradeService.classGradeUpdate(classGrade);
        return new ResponseEntity<>(HttpStatus.CREATED);
    }

    @RequestMapping("/classGradeDelete")
    @ResponseBody
    public String classGradeDelete(int  ids)  {
        classGradeService.classGradeDelete(ids);
        return "ok";
    }
}

